home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / non-internet / samba / source / system.c < prev    next >
C/C++ Source or Header  |  1996-06-26  |  6KB  |  225 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    Samba system utilities
  5.    Copyright (C) Andrew Tridgell 1992-1995
  6.    
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.    
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include "includes.h"
  23.  
  24. /*
  25.    The idea is that this file will eventually have wrappers around all
  26.    important system calls in samba. The aim is twofold:
  27.  
  28.    - to enable easier porting by putting OS dependent stuff in here
  29.  
  30.    - to allow for hooks into other "pseudo-filesystems"
  31.  
  32.    - to allow easier integration of things like the japanese extensions
  33. */
  34.  
  35.  
  36. /*******************************************************************
  37. this replaces the normal select() system call
  38. return if some data has arrived on one of the file descriptors
  39. return -1 means error
  40. ********************************************************************/
  41. #ifdef NO_SELECT
  42. static int pollfd(int fd)
  43. {
  44.   int     r=0;
  45.  
  46. #ifdef HAS_RDCHK
  47.   r = rdchk(fd);
  48. #endif
  49.  
  50. #ifdef HAS_TCRDCHK
  51.   (void)ioctl(fd, TCRDCHK, &r);
  52. #endif
  53.  
  54. #ifdef HAS_FIONREAD
  55.   (void)ioctl(fd, FIONREAD, &r);
  56. #endif
  57.  
  58.   return(r);
  59. }
  60.  
  61. int sys_select(fd_set *fds,struct timeval *tval)
  62. {
  63.   fd_set fds2;
  64.   int counter=0;
  65.   int found=0;
  66.  
  67.   FD_ZERO(&fds2);
  68.  
  69.   while (1) 
  70.     {
  71.       int i;
  72.       for (i=0;i<255;i++) {
  73.     if (FD_ISSET(i,fds) && pollfd(i)>0) {
  74.       found++;
  75.       FD_SET(i,&fds2);
  76.     }
  77.       }
  78.  
  79.       if (found) {
  80.     memcpy((void *)fds,(void *)&fds2,sizeof(fds2));
  81.     return(found);
  82.       }
  83.       
  84.       if (tval && tval.tv_sec < counter) return(0);
  85.       sleep(1);
  86.       counter++;
  87.     }
  88. }
  89.  
  90. #else
  91. int sys_select(fd_set *fds,struct timeval *tval)
  92. {
  93.   struct timeval t2;
  94.   int selrtn;
  95.  
  96.   do {
  97.     if (tval) memcpy((void *)&t2,(void *)tval,sizeof(t2));
  98.     errno = 0;
  99.     selrtn = select(FD_SETSIZE,SELECT_CAST fds,NULL,NULL,tval?&t2:NULL);
  100.   } while (selrtn<0 && errno == EINTR);
  101.  
  102.   return(selrtn);
  103. }
  104. #endif
  105.  
  106.  
  107. /*******************************************************************
  108. just a unlink wrapper
  109. ********************************************************************/
  110. int sys_unlink(char *fname)
  111. {
  112.   return(unlink(dos_to_unix(fname,False)));
  113. }
  114.  
  115.  
  116. /*******************************************************************
  117. a simple open() wrapper
  118. ********************************************************************/
  119. int sys_open(char *fname,int flags,int mode)
  120. {
  121.   return(open(dos_to_unix(fname,False),flags,mode));
  122. }
  123.  
  124.  
  125. /*******************************************************************
  126. a simple opendir() wrapper
  127. ********************************************************************/
  128. DIR *sys_opendir(char *dname)
  129. {
  130.   return(opendir(dos_to_unix(dname,False)));
  131. }
  132.  
  133.  
  134. /*******************************************************************
  135. and a stat() wrapper
  136. ********************************************************************/
  137. int sys_stat(char *fname,struct stat *sbuf)
  138. {
  139.   return(stat(dos_to_unix(fname,False),sbuf));
  140. }
  141.  
  142. /*******************************************************************
  143. don't forget lstat()
  144. ********************************************************************/
  145. int sys_lstat(char *fname,struct stat *sbuf)
  146. {
  147.   return(lstat(dos_to_unix(fname,False),sbuf));
  148. }
  149.  
  150.  
  151. /*******************************************************************
  152. mkdir() gets a wrapper
  153. ********************************************************************/
  154. int sys_mkdir(char *dname,int mode)
  155. {
  156.   return(mkdir(dos_to_unix(dname,False),mode));
  157. }
  158.  
  159.  
  160. /*******************************************************************
  161. do does rmdir()
  162. ********************************************************************/
  163. int sys_rmdir(char *dname)
  164. {
  165.   return(rmdir(dos_to_unix(dname,False)));
  166. }
  167.  
  168.  
  169. /*******************************************************************
  170. I almost forgot chdir()
  171. ********************************************************************/
  172. int sys_chdir(char *dname)
  173. {
  174.   return(chdir(dos_to_unix(dname,False)));
  175. }
  176.  
  177.  
  178. /*******************************************************************
  179. now for utime()
  180. ********************************************************************/
  181. int sys_utime(char *fname,struct utimbuf *times)
  182. {
  183.   return(utime(dos_to_unix(fname,False),times));
  184. }
  185.  
  186. /*******************************************************************
  187. for rename()
  188. ********************************************************************/
  189. int sys_rename(char *from, char *to)
  190. {
  191. #ifdef KANJI
  192.     pstring zfrom, zto;
  193.     strcpy (zfrom, dos_to_unix (from, False));
  194.     strcpy (zto, dos_to_unix (to, False));
  195.     return rename (zfrom, zto);
  196. #else 
  197.     return rename (from, to);
  198. #endif /* KANJI */
  199. }
  200.  
  201.  
  202. /*******************************************************************
  203. chown isn't used much but OS/2 doesn't have it
  204. ********************************************************************/
  205. int sys_chown(char *fname,int uid,int gid)
  206. {
  207. #ifdef NO_CHOWN
  208.   DEBUG(1,("Warning - chown(%s,%d,%d) not done\n",fname,uid,gid));
  209. #else
  210.   return(chown(fname,uid,gid));
  211. #endif
  212. }
  213.  
  214. /*******************************************************************
  215. os/2 also doesn't have chroot
  216. ********************************************************************/
  217. int sys_chroot(char *dname)
  218. {
  219. #ifdef NO_CHROOT
  220.   DEBUG(1,("Warning - chroot(%s) not done\n",dname));
  221. #else
  222.   return(chroot(dname));
  223. #endif
  224. }
  225.